package com.company.edit;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;


/**
 * Created by v on 17-4-10.
 */
public class Pretreatment {
    //去除html中的<br>和<br/>
    public static Document wipeOfBr(Document doc){
        doc=replace(doc,"<br>","\n");
        doc=replace(doc,"<br/>","\n");
        return doc;
    }

    //用特定字符串替换掉原来在html中所存在的字符串
    public static Document replace(Document doc,String target,String replacement){
        String html=doc.toString();
        html=html.replace(target,replacement);
        return Jsoup.parse(html);
    }

    //去除html中的<strong>
    public static Document wipeOfStrong(Document doc){
        doc=replace(doc,"<strong>","");
        doc=replace(doc,"</strong>","");
        return doc;
    }

    //去除不可能的标签
    public static void wipeOfNoise(Element element){
        //去除种不可能的标签
        element.select("ul").remove();
        element.select("input").remove();
        element.select("form").remove();
        element.select("dl").remove();
        element.select("script").remove();
        element.select("style").remove();
        element.select("img").remove();
        element.select("select").remove();
    }
}
